package com.ssy.lingxi.common.constant.settle;

import com.ssy.lingxi.common.language.LanguageHolder;
import org.springframework.util.StringUtils;

import java.util.Arrays;

/**
 * 结算单据类型枚举
 * @author 伍将
 * @date 2020/10/21
 * @version 2.0.0
 */
public enum SettlementOrderTypeEnum {

    /**
     * 所有单据类型
     */
    ALL(0, "所有单据类型"),
    /**
     * 生产通知单
     */
    PRODUCTION_NOTICE(1, "生产通知单"),
    /**
     * 物流单
     */
    LOGISTICS(2, "物流单"),
    /**
     * 订单
     */
    ORDER(3, "订单"),
    /**
     * 积分订单
     */
    SCORE_ORDER(4, "积分订单"),
    /**
     * 退货申请单
     */
    RETURN_GOODS(5, "退货申请单"),
    /**
     * 请款单
     */
    APPLY_AMOUNT(6, "请款单"),
    /**
     * 物料对账单
     */
    RECONCILIATION(7, "物料对账单"),
    ;

    private final Integer code;
    private final String message;

    SettlementOrderTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getMessage(Integer code, String content) {
        SettlementOrderTypeEnum item = Arrays.stream(SettlementOrderTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(ALL);
        return (item.getCode().equals(APPLY_AMOUNT.getCode()) && StringUtils.hasLength(content)) ? (item.getMessage() + ":" + content) : item.getMessage();
    }
}
